﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Windows.Forms;
using System.IO;

namespace RenameFilesUtility
{
    /// <summary>
    /// Logique d'interaction pour MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private FolderBrowserDialog fbd;

        public MainWindow()
        {
            InitializeComponent();
            fbd = new FolderBrowserDialog();
        }

        private void OpenRepertoryButton_Click(object sender, RoutedEventArgs e)
        {
            fbd.ShowDialog();
            selectedFolderLabel.Content = fbd.SelectedPath + @"\";
            resultLabel.Content = "";
        }

        private void RenameAllFilesButton_Click(object sender, RoutedEventArgs e)
        {
            int cpt = 1;

            foreach (string completefilename in Directory.GetFiles(fbd.SelectedPath))
            {
                string oldfilename = completefilename.Substring(completefilename.LastIndexOf(@"\") + 1);
                //string newcompletefilename = fbd.SelectedPath + @"\" + cpt + "-" + oldfilename.Replace("-", "");
                string newcompletefilename = fbd.SelectedPath + @"\" + oldfilename.Substring(oldfilename.LastIndexOf("-") + 1);
                File.Move(completefilename, newcompletefilename);

                cpt++;
            }

            resultLabel.Content = "Success";
        }
    }
}
